package com.zzxz.practicaltrainingsys.mapper;

import com.zzxz.practicaltrainingsys.vo.GroupVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GroupVoMapper {

    // 根据项目ID获取所有小组基本信息，并验证教师权限
    @Select("SELECT " +
            "t.team_id AS teamId, " +
            "t.group_id AS groupId, " +
            "t.team_name AS teamName, " +
            "tp.topic_name AS topicName, " +
            "s1.student_name AS leaderName, " +
            "s1.student_sex AS leaderGender, " +
            "s1.student_id AS leaderId, " +
            "s1.student_phone AS leaderPhone, " +
            "s2.student_name AS viceLeaderName, " +
            "s2.student_sex AS viceLeaderGender, " +
            "s2.student_id AS viceLeaderId, " +
            "s2.student_phone AS viceLeaderPhone " +
            "FROM team t " +
            "LEFT JOIN topic tp ON t.topic_id = tp.topic_id " +
            "LEFT JOIN student s1 ON t.leader_id = s1.student_id " +
            "LEFT JOIN student s2 ON t.viceleader_id = s2.student_id " +
            "INNER JOIN project p ON t.project_id = p.project_id " +
            "WHERE t.project_id = #{projectId} " +
            "AND p.teacher_id = #{teacherId}")
    List<GroupVo> getGroupsByProjectIdAndTeacherId(@Param("projectId") Integer projectId, @Param("teacherId") Integer teacherId);

    @Select("SELECT s.student_id AS studentId, s.student_name AS studentName, s.student_sex AS studentGender, s.student_phone AS studentPhone " +
            "FROM member m " +
            "JOIN student s ON m.student_id = s.student_id " +
            "WHERE m.team_id = #{teamId} " +
            "AND m.student_id NOT IN (#{leaderId}, #{viceLeaderId})")
    List<GroupVo.MemberVo> getTeamMembers(@Param("teamId") Integer teamId,
                                          @Param("leaderId") Integer leaderId,
                                          @Param("viceLeaderId") Integer viceLeaderId);
}
